package cn.wolfcode.controller;


import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
 @RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    //查询所有部门
    @GetMapping()
   public Result list(){
      List<Dept> list = deptService.list();
     return Result.success(list);
   }
   //根据ID查询 部门
    @GetMapping("/{id}")
    public Result get(@PathVariable Long id){
      Dept dept = deptService.getById(id);
      return Result.success(dept);
   }

   //添加部门
    @PostMapping
    public Result add(@RequestBody Dept dept){
      deptService.add(dept);
      return Result.success();
   }
   //修改部门
    @PutMapping
    public Result update(@RequestBody Dept dept){
      deptService.update(dept);
      return Result.success();
   }
   //删除部门
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
      deptService.delete(id);
      return Result.success();
   }

}
